/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.umss.arqui10.modelo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.TreeMap;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * To manage the historial and current prices
 * @author rho1and0
 */
@Entity
public class Price implements Serializable {
   
    @Column
    @Id
    private TreeMap<Date, BigDecimal> historicalPrice;

    /**
     * Default Constructor made a new TreeMap of prices
     */
    public Price() {
        this.historicalPrice = new TreeMap<Date, BigDecimal>();
    }

    /**
     * Get the price for today
     * @return current price
     */
    BigDecimal getCurrentPrice() {
        return getPrice(new Date());
    }

    /**
     * realizar la busqueda pensando que puedo realizar inserciones de precios
     * futuros
     * @param date
     * @return the price valid for date
     */
    BigDecimal getPrice(Date date) {
        return this.historicalPrice.floorEntry(date).getValue();
    }

    /**
     * @param price
     */
    void changeCurrentPrice(BigDecimal price) {
        BigDecimal put = this.historicalPrice.put(new Date(), price);
    }
}
